breaking down main to smaller functions