Pattern-match directly against `list` instead of `list.headOption.getOrElse(null)`
Use built-in `sum` method