Updated code to work in coffescript and javascript