Added test cases and code modifications