replace Either with custom error handling