Might be better to call result.error in the if block below rather than passing result into the helper functions.

That would make the flow more clear.