Refactor common functions to common.ex