Moved main loop to function