optimization part refactoring