cleaner with flatMap
Fix type erasure warnings
Fix non-exhaustive match