refactor patch.js