Optimization permission and some refactoring