Cleanup
Bugfix, and started writing on tests.