Re-write locking to support transactions.