fixed some portability problems on freebsd (and possible other oses)