refactor code using coffee script