heavy refactoring - stream layout improvements