Fixed some race conditions