readability + performance, functions outside loop
removed dependency on $scores in main