Minor tweaks to attempt to fix bugs. Added debug display.