fixed some potential bugs reported by the static analyzer