fixed bug where too many images could use up all memory