last steps for sequential HT

translated barbaras python code