Fix undefined variable errors