JSLinted code and added some comments and improvements.