Race condition sample + refactoring