moved gateway_hash creation outside of only_if control