Spruced up code

Made it more jshint friendly. Also, refactored quite a lot of code.
Merge pull request #1 from shash7/master

Spruced up code