Initial implementation of diagnostic.  A lot of debugging code remains.