refactored to use Try instead of Either where appropriate