Make script more robust

Don't assume share is the first query parameter.
Split url utility functions into separate module

Makes it easy to unit test
Add tests for urlutil