fixed bug when length of input is exactly n blocks