Refactor: Use thread last macro where appropriate
Refactor: Simplify flatten method
Refactor: fuse calls to map