refactor the store function