refactoring to organize callbacks and reduce number of jquery objects