fixed building on mingw32
fixed errors
optimization