Replaced poll with select for MacOSX