The previous $lock never gets used, probably shouldn't be an else?