refactor to decrease the amount of copypasta

Change-Id: Ib540d79034f1963905685c1282d091bc034cf4f3