Put the main loop into its own function, added comments and vague license details.