Finish history function