factor out code normalization