There is too much going on in this line.  Why are we indexing to [0]?  You need at least a comment explaining the structure of these variables, and probably to separate the logic into several separate lines.