More safety checks, small refactor