finished simplifying code. the triangle dance has errors as the back references aren't fixed