changed the implementation so arrays are from heap instead of stack