Fix local variable reference detection