finish connect middleware and handler logic