Improved AJAX handling