Moved main loop into own function