Performance improvements for reductions

- Partial improvements to scan algorithm
- Fixes #217