replaced copied variables with references in functions