Working generic template.
Condensed the code.