Fixes for dependencies in templates and clean up

I've made a fix for the error that happened when there was a template in the xpd.xml. I've also done a general cleanup exercise of error messages, spacing, etc.