refactored functions for counting score and ending game