Handle errors
Move url resolving into a different function