Refactored to abstract stream reading