Refactored code and made it jshint compliant.