Updated saving data to db function