Cleaner safety checks

Moved safety check into a function for easier future editing and
readibility.