Updated code with test cases.
Updated code with test cases.