A bunch of refactoring and changed the 'generateUri' method