Added new tests, refactoring