Adding check for deadlock