trim changed to while loop