Changed a lot of the programming to be in a function.