I think you can use esp.contains(ep) here to dedup instead of for loop etc.