updated to a more idiomatic solution