split common functions to fns.sh