Fix segfaults, ready for public testing (TODO lm-scale)