Better locking; save on close now works properly