Refactor task.js