reworked auto-detection code, small tweaks and works now on osx