task: check is_empty first, before is_closed to reduce checks.