Much logging, and some logic fixes.