Fixing some logic with atomic increment