added intermediate Option step before introducing flatMap