Refactor logic.js to be less redundant