Implemented most of the scaling factor code.