more elegant way of calculating set intersection