Fix some Windows-only crashes

...and some variable-shadowing.