Ajax refactor