caught segfaulting error = not correctly freeing memory after using in strtok_r. Also, cleaned up code so that the defs proceed executable statements