Added methods for stream, refactored code