added close before connect