Revert "Revert "Performance increase in thumbnail handling""

This reverts commit 0a1a9a910cd1a46b3ef070072dd2012e4ddd7e84.