refactoring code based on the backbone.js tutorial