Part 1 of the template system. Also some other changes are made.