added the scaling algorithm