implementing wavefunction