refractor approve.js file