Used Mako inheritance in templates

Reduced code repetition significantly in templates.