Fixing race condition and other mistakes. Fixes #1603.

// FREEBIE
brace on a newline please