Major code refactoring to use templates

First working state, very incomplete.
Specifying daux-theme specific variables.