found some bugs with malloc's allocation.