Commented and cleaned up AJAX code