Added record locking logic