further ported code from ilwis 3.8