Moved template to external user-setable file, more code cleanups and style improvements.