Fix streaming and refactor.