Refactored to make the sample more idiomatic