added states and do while block for connect