Move url creation to separate function to make it easier to test, created unit tests and simplified the code.