eliminate some duplication with a bit of CPP