refactor logic.js