refractoring of dsr.py