Reverting optimization permission and some refactoring