Fix #45, Fix #42. Moving from coffee to js. Refactoring code.