added nil check for custom_env