Code cleanup & templating enhancements