global rearangment and encapsulation of functions