Refactor files into namespaces.

Store initial global environment in vars for easy resetting of state.