Fixes #3884 #4014 in twig branch