Added some debugging stuff to look at deadlock issue. It gets into a local maximum problem.