refactor ajax calls into functions