Patch metrics

Code cleanup and new function for process fidelity.