Refactoring in select