Implement refactoring for thumbnails functionality with js closures