fixed max callstack exceeded errors and improved streaming support