Modified normalize function