changed malloc to calloc, sort of fixed free() giving my problems