Refactor code, use select().