refactor to be more idiomatic