add LOCKFN variable, simplified some locking code