added checks for locked before unlocking