Fixing race conditions more intelligently