Nice to see all the common code pulled out into a function.