[WIP] Unittests

Trying to unittest as much as possible.
This is work-in-progress so please comment on the tests.