patch refactor