freeing memory after every iteration