added deadlock protection