fix mysterious segfaults with mysterious code