Factor out AJAX calls into their own functions