Fixed various bugs in codegen sample programs.
Updated documentation.