Squashed AJAX bug, cleaned up code