Fixed problem with early references and added judicious debugging statements to find out about type error. NO TEST: fixing something that was wrong earlier and just adding extra output.