This patch adds and improves debugging output. No functionality changes.