Adding unit tests & integration test and fixing bugs to make unit test pass.