select() implementation - Code cleanup and meaningful comments