fixed problem with print loop and refactored with suggestions from nodeschool issues tracker