corrected upgrading and inserting in datbase