code cleanup of codegen and additional unit tests