some adjustments made so code will compile without errors or warnings on FreeBSD