add scoring, some refactoring of code