refactored and moved array building to methods