Internal: removed some duplicate casts, marked some classes is IDisposable, some streams were disposed more than once.