Extract common code