more refactoring, more test cases