Cleaned up JavaScript as per JSLint