updated functions to get the environment correct