improves gallery calculation