Refactored code after running it through JSLint. Updated tests.