Fixed getClosestState() by adding 1 and changing sorting order.