update - fixed bug if n was larger than array.length