fixed dynamic memory(indices were off)