fixed weird errors by allocating image structures on the heap