Optimize dataset construction.