Refactor the store algo substantially