Fixed code to be more idiomatic.