moar tests!

And some little refactoring.