tried to refactor to move dependencies out, ran into issues about the scope of the "env" variable