Moved more code into Twig templates