Move common function to library