Split global state into its own file

Zach Weinberg suggested this as github issue #2.