Reimplemented the comparisons as two for loops (much faster than LINQ)