Refactor save to db method