unified env code a bit, reworked extend