another bunch of optimizations and inlinings in the capture loop