Performance optimalization, closing streams, removed unused methods