Fixed logic to optimize wdensity