Corrected some conditions in the function getFrame()
Added memory leak control in getImage()