Some more code simplifications using `as` and `compact_map`