Refactoring, added more tests