Fix AJAX race condition