Computing scaling factor only once and refactoring