Ported smooth scaling from sgs2 code