refactored lightbox code