Fixed a few bugs with AJAX