added disconnect message code, and loop block