cygwin compatible setup and some func re-arrange