Changed scaling algorithm for better stability