Added helper functions to generate thumbnails with less code.