Add error function, fix some stuff in CodeGen