Break out code into some functions.