Various restructuring to reduce code size.
Some small size optimizations.