More efficient implementation of history logic