Fix some issues that can cause random failures