Original commit message from CVS: Added some more testcases and rearanged some code (it's still pretty stupid)