Refactor patch according to review suggestions