Clean up wave function calculations and fix minor errors