switched maxImageId to maximum image id in table