Remove Main.prog dependencies and fix custom definitions.

Also lots of architectural cleanup as well.