Fix some bugs/omissions. Left in many debug prints and tests.