improve ajax handling