made the code more idiomatic