fixing infinite loop printing