Basic deadlock detection implemented (needs some testing)