Improved cleanup process.
Moved stream logic to stream file.
Added comments.