Refactored some loops to be more idiomatic