better and fewer loops; catch NaN's in consolidate()
tweaks