wrote a function to initialize the state used for reordering