beginning em phasing refactor to phasing.R