More work on bug #7636.
This fixes bug #7637.  Also some work on bug #7636
This fixes bug #7636.