Templates and main code.