refactor ajax callback