updated
now with dynamic allocation