Duplicated functionality from beregam