Parser and templates refactor

Huge refactor and reorganization of the XML parser, JSON database and templates no user-facing changes, but nicer code with less redundancy