Added conditional to prevent unnecessary AJAX calls