Some cleanup
Fix race condition