added better ajax handling