Add loops and improve wrong variable detection