a great deal of diagnostic debug logging plus some commenting