You probably want to move the leave outside the if () block?

(Dunno if you want the lock only around the assignments here or not)