updated ajax calls with error and loading to be more reliable