Put the main while loop into a function main()