refactoring scaling logic