first version of rewrite to preallocate data vec.