Tiny refactoring ideas from http://javascriptplayground.com/blog/2013/06/refactoring-js/.
Also added few JSDoc lines