Pull out onConnect logic to a separate file