changed connect midware sequence