implemented longest prefix match