Clean epoch extraction code