nasty bug: need to call select() instead of sleep() -- causes control flow to
block for too long