added some safety belts

to fix some potential issues reported by the static analyzer