cleanind up optimizeSizes function