Fixed some race conditions.
More race conditions. Should close #1