finished refactoring as callbacks, and passed JSlint