further works towards profiles. Some refactors along the way, too.