Added some deadlock protection.