Extract logic for create arrays