Done some fixes and added test cases