Refactor pileup codes