WIP: fix incorrect calculations of phase advance

Do not merge this yet.