Fix Windows compile errors and threading error

Fixes from the previous merge