majour rework. now automatically allocates array for storing data.