improved thumbnailing algo