improve js for gallery