Using shared_ptr for better memory management.
Optimizated score calculation.