Minor improvements

I have added some code style cleaning. Remove some unused or obsolete imports, or obsolete usage of some variables on templates.

Also I have created some functions that replaces repeated code creating urls.

This code is not tested and can not be merged without previous revision.