fixed memory leak caused by not freeing structs