Thread safety

Fairly obvious changes to add thread safety. Little thought given to performance, since this is a debugging tool.