Wrote a gen_wavefunction function function function