cleanup and memory leak fixes
fix compile and run errors in windows