Refactored flatMap, orElse, and filter to not use pattern matching