Refactoring for ajax progs