Changed method of saving data to database