Use transactional connection in  insertIntoHistory
Call updateUserTime() wherever possible