fixed bugs and tested on latest cygwin