Pulled the variables out of the submit handler for slightly better organization, and to keep all of the functions as light as possible.