Added unit test, improved the design and tested more