split out repetitive tasks into functions