Compatibility, template, security level fixes

Improved compatibility with older python versions; tweaked templating;
and also improved security level logic.