Added a check for smaller arrays