refactored delta optim. code a bit