Fix some bugs in gallery