Fixed a small bug in getNext().