Solved by harsha_g in post #2 
              
              
                If you see this part of the code, you are only returning one element but in the for loop you are expecting 2 elements and hence the error.