finish length function