refactor function name; add prints; remove global vars