move port declaration to inside loop because we close it every time