Added error handling on all functions.
Switched from using Option to Result for reporting errors.