Revised lastrepeat implementation.