Refactoring ajax lib