Fix undefined variable errors

Use the correct variables