refactor remove the extra function

The `URLs` and `PeerURLs` share the same logic, expect one function call. 
Combine them by using function pointer.