Made Clang Analyzer happy by removing dead code, adding some assertions and fixing theoretically unsafe code.