Refactoring and cleaning up
Throw error on invalid url