Fix undefined variable bug