Refactor tasks.js.coffee and fix minor bugs