Removed some race conditions