updated to work on FreeBSD