Refactor getScore function