refactor storage code to put more logic in the model.