Refactored to build array in final loop, rather than string