refactors ajax calls