extracted common functions into library