cleaned up string formatting and iterators in while loop