added var to the variables to avoid global declaration