Refactor ajax