rewrote almost everything with pointers