Fix logic in is_safe