fix numerous memory leaks; add missing dealloc methods; convert some properties to methods when they were not backed by ivars; remove some unreachable code after raised exceptions; remove some unused imports
merge with origin master