Refactor to add FreeBSD support.