Fixed a number of bugs reported by new analyzer