Adds comments and refactors code in main.coffee