more refactoring of the javascript.  Now all callbacks are separate functions