Code cleanup, revamp connection process