Lots of duplicate code removal.