Pull out more stuff into sharable functions.
More FreeBSD support.