Move stuff into a main function