Refactored to prevent cases that result in a thumb image being smaller than expected