tracking down a bug dhthell found, added asserts and better logging.