Move some common functions into shell libraries