finished functionality of AJAX