Lung function optimization