Dev merge 2

Merge from newest master + fixes needed on FreeBSD.