Removed many calls to malloc and had functions take in pointers that would then be modified