Moved common functions to library