fix variable scope in patch.js