Bit of refactoring of the code for readability.
Added support for url templates in stubs.