Factor out common code

Change-Id: I2375320bbe2aa5588af5d2cd763f8fd93f69d9a7