Add sample optimization code