refactor the stream compression