Optimization working with long lines