This code runs on every redraw and iterates the whole tracks list, which is something we should avoid.