off-by-one bug that managed to evade me until now