more idiomatic code and a logical fix