fix accessing undefined variable