This check is repeated a few times- can you please create a method, e.g. `is_empty`?