Extract common code into method.