Refactor to allow easier extension/behavior.

Users can now override various methods to change the generated code or
add to the generated code.