fixes to set_state to avoid infinte loop on AJAX error - close #579