more idiomatic scala function