Refactor common-functions.sh