select: converted a function and wrote required utility functions.