Added optimization to reduce CAS instructions.