ENH Refactor scaler code