add score function and fixed some bugs