Function|clean-up

Add a function for calculate score and clean-up the code