Fixed using wrong variable, causing several errors