Rewrite select function using `cons' instead of `append'