Reducing global variables. Minor tweak. Working version.