partially refactored code; score now gets its own function