Uncollapsing the wavefunction by undoing quantum measurements