copied most logic from wrapper.  droped cygwin support