updated code and test cases