Move track process to a separate function instead of doing it in the loop.