Modified solution to be more idiomatic