Change data flow for better memory consumption