Implement history

Not performant yet (see comment), but works fine!