Minor code redesign and check vars visibility.