Improvements to set_molecules function.