update history and insert records