Ajax refactoring