Changed to single AJAX request. Fixed several bugs