Optimized the example train code.