optimization: use lists instead of arrays