Refactor a bit and introduce unified history