Added unit tests
Some minor refactoring
Addressed comments