refactor for wagtail