Some minor flatten fixes, main algorithm still not updated.

- Fix parameters passed to internal flatten call.
- Expand input before flattening.
- No changes made to algorithm to comply with spec updates.