Refine code for updating data in table