Codegen improvements

Change-Id: I3d2d2e7e9f970dda8ccb4e729fdbfbdeb1dd9a06