cleaned up TDS code