refactoring ajax calls