added test cases and implementation