Bug fixing, changes for Windows compatibility