redesign how data is stored to avoid permanent running counter variable