modified to use pointers