More idiomatic error checking