restructured the code and completed test cases