fixed a lot of bugs under Windows