Refactoring the program to allow for functions.