Make things more or less thread-safe by passing around context rather than using globals
This shouldnt be here
Merge pull request #1 from mkoppanen/master

Quick poke at thread-safety