Adding unit tests
Full refactor