Race fixes

This includes the commit from #50.

I don't know if these are the ideal fixes. It feels a little haphazard, and there probably needs to be more thought about how concurrency is handled generally rather than just trying to squash them as the race detector finds them.

This does remove all the races that the race detector finds in my unit tests (which are a couple more than proxy_test.go finds). I'm going to test it overnight with all my platforms and see if this reliably resolves the corrupted data I was seeing in #48.