Refactored Twig extension