The origin of chemical elements heavier than iron, such as gold, has been a long-standing puzzle. About half of the heavy-element abundances are expected to be produced by the astrophysical rapid neutron capture process, the r process. Its astrophysical site has been one of the biggest outstanding questions in physics. The observation of the binary neutron-star merger GW170817 and the associated kilonova in August 2017 gave the first direct evidence that the r process takes place at least in such neutron-star mergers. However, there are still several open questions related to the r process. Can neutron-star mergers explain all observed r-process abundances? What is the role of supernovae in the production of heavier elements? How to interpret the observed kilonova? In order to better model the r process, accurate nuclear physics input data are needed. Nuclear masses are one of the most important nuclear physics inputs for the r process and for studying the chemical evolution in the Cosmos. In this project, we have performed around 170 high-precision atomic mass measurements that serve as important inputs for modelling the r process. Around 55 long-living isomeric states, which can also play a role in the r process, were resolved from the ground states and measured using novel measurement techniques. New isomeric states were discovered during the project. Around 40 atomic masses were experimentally determined for the first time, thus extending the knowledge of neutron-rich nuclei and reducing the mass-related uncertainties in the r-process calculations. Post-trap decay spectroscopy was employed to identify which state was measured in order to avoid systematic uncertainties in the mass values, and also to provide further information on beta-decay properties and nuclear structure which also affect the r-process calculations. A new gas cell and target platform have been designed, manufactured and successfully commissioned to produce heavier neutron-rich nuclei via multinucleon-transfer reactions at IGISOL. The new data gathered in this project have been compared with theoretical nuclear models and included in the astrophysical calculations. The improved r-process calculations are essential to fully benefit from the anticipated new multimessenger observations from neutron-star mergers. This project has advanced our knowledge of nuclear structure far from stability and reduced nuclear data uncertainties in the r-process calculations, which can potentially constrain the astrophysical site for the r process and help to understand the origin of heavier elements.