fix bug and add scale factor