cleaned up the code, passes JSLint