code works, memory problem is solved.