Port to FreeBSD. Code cleanup and comments.