moved malloc/free to arrays. spares one pointer dereference.