Added lock handling