Refactor the original NetBSD code into mostly shared code with other BSDs