refactored to use each_cons @fjennet might be interested?