more cleanup and logic normalization