Added unallocation of memory after every iteration!