in task2, RefCell is used since the passed state in 'scan' seems to be immutable, although it shouldn't.