ported some parts from the text-infra-structure