Structured code a bit.

Make a separate utility.h, and differentiated rules a bit.
Adding prior changes.