Clean up some types, switch to beginthread on Windows