Needs cleanup, but works on windows