Fix code to run on FreeBSD