create refactored with all test cases passing