Added tests
Squashed a lot of bugs