found an error-less implementation that works on windows (phew! .. ugly...)