added check for open ports to exit function