fixed normalize function