extracted common code