Fix historical data code