Added flockfile calls to reduce i/o overhead