Fix bug when loading image gallery