more idiomatic way of handling errors