Fixes thumbnails scrolling and refactors code (#3230)