Refactored code to use ResultTask instead of Maybe