Fixed the removal of transients.

Fixed to account for the states with no histories of length L_max-1, by
‘wrapping’ the histories of length L_max.