Compile and run on FreeBSD (tested on 9.1)

Changes made to compile and run on FreeBSD (tested on 9.1)