Quick poke at thread-safety

This change uses a struct to hold the variables rather than globals.