Move common code to a helper script