Fixing code gen, adding new error logging