some of the Hans's suggested code changes, plus some test enhancements

I will fix up amg_cycle next.