Halfway done refactoring. Removed all known globals. Implemented simple
testing suite.