refactored error handling from an inout to using Result