more leftrec fixes: head caching and input rewinding