bugfix - function using wrong variable