Change from js to coffee and refactor some code