Tests and free memory corrected
Freeing of memory fixed