Added some tests, small refactoring