removed improper exit program from function, added main loop to main()