Check results of dynamic_cast, add missing initializations, remove unused variables
(from Coverity reports)