minor refactoring: updated type checks for error reporting and removed unnecessary (ugly) allocations used for consuming stream