FreeBSD support as well as some assorted fixes