pulled generic functionality out into separate cpp file.