fact program. does not terminate
change iteration order
output
minor fix