Fixed windows build + some optimizations