changed data array to be dynamic and added destructor