added generateUrl() method.
REFACTORING, refactor some method and logic