create functions to clean up redundant code