Also this check should be deduplicated into a function