refactoring, coffeescript used
tests added