[WIP] Thumbnail fixes

:construction: some fixes and refactoring for the thumbnailing code

cc @DeepDiver1975