fixes for different length of the last piece.