fixed heap corruption

new int(x) should be written as new int[x];
should delete[] array after new [];
a little re-formatting;