Fixed my problem and added simple deadlock detection