Revised for different lengths