refactor some ajax calls