works but not at every iteration; could not fix memory deletion problem