Refactoring chan global variable
Implementing stream data handling