Added file locks as sometimes I suspect it was getting errors because of multiple processes accessing same file