Modified to work on windows mingw (@justinvdm)