Added some tests
Refactored, fixed problems caused by refactoring