Refactored code and added coffeescript