Getting close, but there's a bug in indexOfClosest...