Fix windows compatibility

Please apply these commits (after testing my fork on linux :P)