Windows support, bit of refactoring