Start of BSD fixes (issue #216) thanks @yalla