refactoring select and with