edited so that the listing of factorN() only includes the function, not the surrounding code