simplify code with a Result type