added retries for poll_terminal() & fixed error codes