fix logic errors related to historyStack