converted wiring to a function based on feedback frmo Eugene