Condensing repeated portions into subfunctions