fix a couple of crash prone situations