Adjusted alogirthm for img sizes