Fixed JSLint errors and function