Fix undefined variable exception