simplify and handle where result can be nil

Simplify and handle when result can be nil. {On an updated branch}