Added clause in ipos() for when x == xmax