smarter select function