added global environment, still needs a bit of work, but tests pass