Added try-finally to locks