Fix various bugs uncovered during testing on Linux