changed to pointers and malloc