fixed iterator bug, error messages, factored code
merged my changes with recent version!