Updated save to database code.