Fix a very nasty crash bug (reported by jd et al)