Resolve infinite loops for ports, fix #653