factored large function into multiple smaller functions