factored envelope out of functions