Added defer before unlock