Perforance fixes, especially for get_links, get_templates and get_templates_all