Ultracold neutrons (UCN) with kinetic energies below 300 neV can be confined for hundreds of seconds, making them ideal for experiments that benefit from long observation times. One of these experiments at the Paul Scherrer Institute (PSI) searches for the CP violating permanent neutron electric dipole moment, probing beyond Standard Model physics. Such precision experiments with UCN are statistics limited. There are worldwide efforts to improve the output of UCN sources. At PSI, comparing simulations of the neutron flux in the deuterium moderator with UCN measurements has lead to new insights into mechanisms limiting UCN extraction. Modified freezing procedures reduce thermal stress in the solid deuterium, increasing the UCN output.