Fixed some bugs in gallery