added ifdefs, fixed strange first-time segfault on windows