modified Critical Section to suit Race Condition