Patches - introduce timing mechanism to fix long patches.

Code improvements and reformat.
Patch checkpoints.