pieceLength not used more than once, eliminate it