Fix bug in port scanning logic