fix bug in gallery appending multiple images