refactoring for better help and less overuse of globals