Fixed undefined variable bug