Only use globals when necessary

See #1