_strdup instead of malloc & strcpy, more memory freeing, structural changes