changing code to use new Result type