Identified bug in AJAX code