Put things in functions

Put the number generating stuff into a function