Made the final changes that Andy did to fix deadlock and debugged.