add score and refactor the code