Replace improper JS for-loops in results page