Fixed template loading. Also overhaul of the complete template loading/saving code.