direction optimization