added unit tests, refactored methods