fixed memory leaks for images