Added normalization of wavefunctions and cleaned/separated some of the code.