Move common functions out into library.