Build lists reversed since it is more efficient. Use a record to track state.