Fix bug for connecting nodes