Fix multithread problem
Fix linux compatibility
most of the fixes needed for making it cross platform
windows worked. need to test on linux