Changes to resolve issues found by the golang race detector. These are just fixed atm, should be looked at for cleanliness of code too