Take out from the while loop the part that should only be run once.