replace acquire lock by 'with' statement