Implement extend_env