Updated function that saves fields in db