Move safe_as_int into utils