Added deadlock detection