Moved flush outside of loop when saving index