after we're done with settling the API this code reduplication ca be reduced here using iteration.