Made the code smaller as I understood stream handling better