Fix windowSurface bug + fix some portability issues