todo.js: refactored syntax and fixed bugs