Not sure why you are only checking the first two elements and assuming they are ids. Also the final clause looks wrong.