Added some tests
Fixes some bugs, added tests