refactor saveToDB