changing name of stream to type. adding checks