Fixed some stuff for windows builds, fixed memory leak