Fixed Windows implementation to be more robust