refactored with the help of JShint