Added error checking for images, removed unused code.