refactor the function getScore.