Broke giant function into smaller functions.