nit: Can we rename this function to something more descriptive? `cpm` doesn't seem immediately obvious.

Also I'd prefer RAII used here.