Clean up code duplicates and let _env_set(target) always return True or None