Refactor out CRUD functions