Improved the locking logics