Fix intermittent test failures/crashes