Fixed few bugs + more unit test cases + cosmetics