refactor optimization