fixed some portability problems on FreeBSD