refactored (multiple streams, dynamic resizing, better logging)